package com.thinkingcoder.tcconfig.client.config;

import java.util.Map;

import org.springframework.context.ApplicationContext;

import com.thinkingcoder.tcconfig.client.listener.TcConfigChangListener;
import com.thinkingcoder.tcconfig.client.repository.TcRepository;

/**
 * tc config service
 */
public interface TcConfigService extends TcConfigChangListener {

    String[] getPropertyNames();

    String getProperty(String name);

    static TcConfigService getDefault(ApplicationContext applicationContext, ConfigMeta configMeta) {
        TcRepository repository = TcRepository.getDefault(configMeta);
        Map<String, String> config = repository.getConfig();
        TcConfigService configService = new TcConfigServiceImpl(applicationContext, config);
        repository.addChangeListener(configService);
        return configService;
    }

}
